
import 'package:cunyutech_flutter_ui/src/text/main.dart';
import 'package:cunyutech_flutter_ui/src/theme/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';


class UnreadRedBadge extends StatelessWidget {
  const UnreadRedBadge({Key key, this.unread, this.child, this.showNumber = true, this.onlyNumber = false }) : super(key: key);
  final int unread;
  final Widget child;
  final bool showNumber;
  final bool onlyNumber;

  @override
  Widget build(BuildContext context) {
    var cs = CYThemeData.of(context);
    Widget content = child;
    Widget number = 
    !showNumber ?
    Container(
      height: 8,
      width: 8,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(4),
        color: cs.failColor,
      ),
    )
    : Container(
      height: 16,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8),
        color: cs.failColor,
      ),
      child: CYParagraph(
        unread>99 ? "99+" : unread.toString(),
        padding: EdgeInsets.symmetric(horizontal: 4),
        alignment: Alignment.center,
        lineHeight: null,
        fontSize: CYFontSize.Small,
      ),
    );

    if(onlyNumber) {
      return number;
    }

    if(unread>0) {
      content = Stack(
        alignment: Alignment.topRight,
        children: <Widget>[
          content,
          number,
        ],
      );
    }
    return content;
  }
}